package com.showcai.controller.downLoad;

import com.showcai.controller.base.WeChatBaseController;
import com.showcai.module.Versions;
import com.showcai.service.VersionsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import java.io.IOException;

/**
 * Created by Baggio on 2018-1-25.
 */
@RequestMapping("/downLoad")
@Controller
public class DownLoadController extends WeChatBaseController {

    @Autowired
    VersionsService versionsService;

    @RequestMapping(value = "index", method = RequestMethod.GET)
    public ModelAndView index() {

        ModelAndView mov=new ModelAndView();
        String views="/index/web/downLoad/index";
        if(getIsMobile()){
            views="/index/wap/downLoad/index";
        }
        mov.setViewName(views);
        return mov;

    }

    @RequestMapping(value = "downloadFile", method = RequestMethod.GET)
    @ResponseBody
    public void downloadFile() {

        Versions versions=versionsService.getLastVersions();
        //String url="http://pulic.oss-cn-shenzhen.aliyuncs.com/showcai/app/XiuCai_V6.2.0_2018_09_20.apk";
       String url=versions.getReleaseAddress();
       if(getIsIPhone()){
           url="https://itunes.apple.com/us/app/qun-xiang-dao/id1436933118?ls=1&mt=8";
       }
         try {
            response.sendRedirect(url);
        } catch (IOException e) {
            e.printStackTrace();
        }

    }


}